﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Avatar.Model;
using AvatarHelper;

public partial class ENewsPaper : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                if (Request["id"] == null)
                {
                    DropDownList1.DataBind();
                    Page.Title += "人才无忧电子报刊 - 第" + DropDownList1.SelectedValue + "期";
                    this.PaperBind(Convert.ToInt32(DropDownList1.SelectedValue));
                }
                else
                {
                    Page.Title += "人才无忧电子报刊 - 第" + Convert.ToInt32(Request.QueryString["ID"].ToString()) + "期";
                    this.PaperBind(Convert.ToInt32(Request.QueryString["ID"].ToString()));
                }
            }
            catch(Exception _e)
            {
                lbl_Error.Text = "出错:" + _e.Message;
            }
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.PaperBind(Convert.ToInt32(DropDownList1.SelectedValue));
    }
    protected void PaperBind(int _id)
    {
        using (var _adc = DBHelper.GetDataContext())
        {
            var _news = _adc.ENewsPaper.FirstOrDefault(n => n.ID == _id);
            if (_news != null)
            {
                lbl_Content.Text = _news.Content;
                lbl_Date.Text = _news.PublishDate.ToShortDateString();
            }
        }
    }
}
